-- 数据选择器（又称多路选择器或多路开关） --
-----------------------------------------
-- 4个地址选择信号（2bit），16个存储单元信号（4bit）
-----------------------------------------


library ieee;
use ieee.std_logic_1164.all;

-- 6输入4输出的查找表
entity data_select is
    port(
        data : in std_logic_vector(5 downto 0);
        dout : out std_logic_vector(3 downto 0);
    );
end entity;

architecture behave of data_select is
    signal s1 : std_logic_vector(1 downto 0);
    signal s2 : std_logic_vector(3 downto 0);
begin

    s1 <= data(5) & data(0);    -- D0,D5作为行
    s2 <= data(4 downto 1);     -- D1-D4作为列

    process(data)
    begin
        
        case s1 is
            when "00" => 
                case s2 is
                    when "0000" => dout <= "0000";
                    when "0001" => dout <= "0001";
                    when "0010" => dout <= "0010";
                    when "0011" => dout <= "0011";
                    when "0100" => dout <= "0100";
                    when "0101" => dout <= "0101";
                    when "0110" => dout <= "0110";
                    when "0111" => dout <= "0111";
                    when "1000" => dout <= "1000";
                    when "1001" => dout <= "1001";
                    when "1010" => dout <= "1010";
                    when "1011" => dout <= "1011";
                    when "1100" => dout <= "1100";
                    when "1101" => dout <= "1101";
                    when "1110" => dout <= "1110";
                    when "1111" => dout <= "1111";
                end case;
            when "01" => null;
                --- 省略...
            when "10" => null;
                --- 省略...
            when "11" => null;
                --- 省略...
            when others => null;
        end case;

    end process;

end behave;


